namespace EFS.Common.Values
{
	public class Boolean : EFS.Common.Values.Generic.Value<System.Boolean>
	{
		/// Implicit constructor
		public Boolean()
		{
		}

		/// Explicit constructor
		public Boolean(System.Boolean value)
			: base(value)
		{
		}

		// Set as string
		public override void SetString(System.String valueAsString)
		{
			// convert number to string for boolean
			System.Int32 valueInt =0;
			if (int.TryParse(valueAsString, out valueInt))
			{
				valueAsString = "false";
				if (valueInt != 0)
				{
					valueAsString = "true";
				}
			}

			// convert string To boolean
			if (EFS.Common.Verify.String(valueAsString))
			{
				InnerValue = System.Boolean.Parse(valueAsString);
			}
		}

		public override bool IsAssignableFrom(System.Type c)
		{
			switch (c.ToString())
			{
				case ("System.Byte"):
					return true;

				default:
					return base.IsAssignableFrom(c);
			}			
		}

		/// Property Inner Object
		public override System.Object InnerObject
		{
			get
			{
				return base.InnerObject;
			}
			set
			{
				// check if input not null
				if (null != value)
				{
					// check type
					switch (value.GetType().ToString())
					{
						case ("System.Byte"):
							InnerValue = (System.Byte)value != 0 ? true : false;
							return;
							
						case ("System.Boolean"):
							InnerValue = (System.Boolean)value ;
							return;

						default:
#if ASSERT
							System.Diagnostics.Debug.Assert(false, "Type mismatch found while checking expected type");
#else
							throw new System.Exception("Type mismatch found while set InnerObject");
#endif							
					}
				}

				// set innerValue
				InnerValue = (System.Boolean)value;
			}
		}

	}
}